<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>规则集细览</title>
    <link rel="stylesheet" type="text/css" href="../bootstrap/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../jqueryconfirm/jquery-confirm.min.css">


</head>
<body style="padding: 20px;">
    <form class="form-horizontal" role="form">
        <div class="form-group">
            <label for="rule_name" class="col-sm-2 control-label">规则集名称：</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="rule_name" placeholder="请输入规则集名称">
            </div>
        </div>
        <div class="form-group">
            <label for="rule_desc" class="col-sm-2 control-label">规则集描述：</label>
            <div class="col-sm-10">
                <textarea class="form-control" id="rule_desc" placeholder="请输入规则集描述"></textarea>
            </div>
        </div>
        <div class="form-group">
            <label for="rule_priority" class="col-sm-2 control-label">规则集权重：</label>
            <div class="col-sm-10" style="width: 200px;">
                <select class="form-control" id="rule_priority">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="rule_type" class="col-sm-2 control-label">规则集类型：</label>
            <div class="col-sm-10"  style="width: 200px;">
                <select class="form-control" id="rule_type">
                    <option selected="selected" value="ActivationRuleGroup">复合规则类型</option>
                    <option value="UnitRuleGroup">单规则组</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="rule_name" class="col-sm-2 control-label">规则脚本：</label>
            <div class="col-sm-10">


                <div id="rule_ul_cen_0" style="padding: 20px;border: 1px solid #ddd;">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>规则名称</th>
                            <th>规则描述</th>
                            <th>规则权重</th>
                            <th>创建时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody id="rule_ul_cen_0_content">

                        </tbody>
                    </table>
                    <!--分页-->
                    <div  style="text-align: center;">
                        <ul id="findgzjdetail_pages_id"  style="margin: 0;"></ul>
                    </div>
                </div>




            </div>

        </div>
    </form>
    <script type="text/javascript" src="../js/request.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../bootstrap/js/bootstrap.js"></script>
    <script type="text/javascript" src="../bootstrap/js/bootstrap-paginator.js"></script>
    <script type="text/javascript" src="../js/jquery.extend.date.js"></script>
    <script type="text/javascript" src="../jqueryconfirm/jquery-confirm.min.js" ></script>
    <script type="text/javascript">
        var findgzjdetaillink = webrootpath+"gzkcate/findgzjdetaillink";//获取规则集内容
        var v_searchdetail_link = webrootpath+"gz/v_searchdetail_link";//查看规则细览
        var v_gz_delete_link = webrootpath+"gz/v_gz_delete_link";//删除规则

        $(function () {
            findgzjdetail(1);
        });
        function findgzjdetail(_pagenum) {
            var opensearchlistid = sessionStorage.getItem("opensearchlistid");
            $.get(findgzjdetaillink,{
                opensearchlistid:opensearchlistid,
                pagenum:_pagenum
            },function (content) {
                if(content.code=="1"){
                    var yc_rule_cate = content.data.yc_rule_cate;
                    $("#rule_name").val(yc_rule_cate.listname);
                    $("#rule_desc").val(yc_rule_cate.listdesc);
                    $("#rule_priority").val(yc_rule_cate.listpriority);
                    $("#rule_type").val(yc_rule_cate.listruletype);
                    var yc_rule_models = content.data.yc_rule_models;
                    var htmlstr = "";
                    if(yc_rule_models!=undefined){
                        for(var i in yc_rule_models){
                            var dataobj = yc_rule_models[i];
                            htmlstr+="<tr>\n" +
                                "<td>"+i+"<input type='checkbox' /></td>\n" +
                                "<td>"+dataobj.modelname+"</td>\n" +
                                "<td>"+dataobj.modeldesc+"</td>\n" +
                                "<td>"+dataobj.modelpriority+"</td>\n" +
                                "<td>"+timestampToTime(dataobj.crdate)+"</td>\n" +
                                "<td>" +
                                    "<button type=\"button\" class=\"btn btn-info\" onclick='v_searchdetail(\""+dataobj.modelid+"\")'>查看详细</button>&nbsp;&nbsp;"+
                                    "<button type=\"button\" class=\"btn btn-danger\" onclick='v_gz_delete(\""+dataobj.modelid+"\")'>删除</button></td>\n" +
                                "</tr>";

                        }
                        $("#rule_ul_cen_0_content").html(htmlstr);
                        findgzjdetail_pages(_pagenum,content.pages);
                    }else {
                        $("#rule_ul_cen_0_content").html("该规则集下暂时没有规则");
                    }
                }else {

                }
            });
        }
        //数据分页
        function findgzjdetail_pages(_pagenum,_pages){
            //处理分页
            $('#findgzjdetail_pages_id').bootstrapPaginator({
                currentPage: _pagenum,
                totalPages: _pages,
                size:"normal",
                bootstrapMajorVersion: 3,
                alignment:"right",
                numberOfPages:5,
                itemTexts: function (type, page, current) {
                    switch (type) {
                        case "first":
                            return "首页";
                        case "prev":
                            return "上一页";
                        case "next":
                            return "下一页";
                        case "last":
                            return "末页";
                        case "page":
                            return page;
                    }
                },
                onPageClicked: function (event, originalEvent, type, page) {
                    findgzjdetail(page);
                }
            });
        }
        /***
         * 删除规则
         * */
        function v_gz_delete(_modelid) {
            var opensearchlistid = sessionStorage.getItem("opensearchlistid");
            $.confirm({
                title:"提示",
                content:"您确定删除此规则吗？",
                buttons:{
                    "确定":function () {
                        $.get(v_gz_delete_link,{
                            modelid:_modelid,
                            opensearchlistid:opensearchlistid
                        },function (msg) {
                            if (msg.code=='1'){
                                findgzjdetail(1);
                                $.alert(msg.msg,"提示");
                            }
                        });
                    },
                    "取消":function () {

                    }
                }
            });


        }


        /***
         * 查看详细
         * @param _modelid
         */
        function v_searchdetail(_modelid) {
            $("#myModal").modal('show');
            $.get(v_searchdetail_link,{
                modelid:_modelid
            },function (msg) {
                if (msg.code=="1"){
                    var dataobj = msg.data;
                    $("#myModalLabel").html(dataobj.modelname);
                    $("#zhixingtiaojian").html(dataobj.modelinit);
                    var modelresult =  decodeURI(dataobj.modelresult);

                    var modelresultarray = modelresult.split("|");

                    var htmlstr = "";
                    for (var i in modelresultarray){
                        var objs = modelresultarray[i];
                        var objarray =  objs.split("^");
                        if (objarray.length==2){
                            htmlstr += "<tr>" +
                                "<td>"+objarray[0]+"</td>" +
                                "<td>"+objarray[1]+"</td>" +
                                "</tr>";
                        }else if (objarray.length==1){
                            htmlstr += "<tr>" +
                                "<td>"+objarray[0]+"</td>" +
                                "<td>"+objarray[1]+"</td>" +
                                "</tr>";
                        }
                    }
                    $("#zhixingdongzuo").html("<table class=\"table\"><caption>结果输出</caption><tbody>"+htmlstr+"</tbody></table>");
                }

            });
        }
    </script>








    <!-- 模态框（Modal） -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                    <h4 class="modal-title" id="myModalLabel"></h4>
                </div>
                <div class="modal-body">
                    <table class="table">
                        <tbody>
                        <tr>
                            <td>执行条件</td>
                            <td id="zhixingtiaojian"></td>
                        </tr>
                        <tr>
                            <td>执行动做（输出结果）</td>
                            <td id="zhixingdongzuo"></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
    <!-- /.modal -->


</body>
</html>